/**
 * 智慧小区管理系统 - 房户管理API接口
 * @author Wu.Liang
 * @date 2024-12-21
 * @updated 2024-12-21 - 完善房户管理API接口，遵循Controller命名规范
 */
import api from '@/api/request'

// 房户相关类型定义
export interface HouseholdData {
  id: number
  householdCode: string
  roomNumber: string
  buildingId: number
  buildingName: string
  unitId: number
  unitName: string
  communityId: number
  communityName: string
  floorNumber: number
  area: number
  usableArea: number
  orientation: string
  propertyType: number
  propertyCertificate: string
  purchaseDate: string
  propertyFeeRate: number
  roomCount: number
  hallCount: number
  houseType: number
  decorationStatus: number
  status: number
  sortOrder: number
  description: string
  fullAddress: string
  residents?: ResidentData[]
  createTime: string
  updateTime: string
}

// 住户相关类型定义
export interface ResidentData {
  id: number
  realName: string
  phone: string
  identityNo: string
  residentType: number
  residentTypeName: string
  moveInDate: string
  status: number
  statusName: string
  createTime: string
}

export interface CreateHouseholdDTO {
  roomNumber: string
  buildingId: number
  unitId: number
  area: number
  roomCount: number
  hallCount: number
  houseType: number
  decorationStatus: number
  status: number
}

export interface UpdateHouseholdDTO {
  roomNumber?: string
  buildingId?: number
  unitId?: number
  area?: number
  roomCount?: number
  hallCount?: number
  houseType?: number
  decorationStatus?: number
  status?: number
}

export interface HouseholdQueryDTO {
  roomNumber?: string
  buildingId?: number
  unitId?: number
  communityId?: number
  floorNumber?: number
  roomType?: number
  houseType?: number
  decorationStatus?: number
  propertyType?: number
  status?: number
  areaMin?: number
  areaMax?: number
  keyword?: string
  createTimeStart?: string
  createTimeEnd?: string
  current?: number
  size?: number
}

// 房户管理API
export const householdApi = {
  // 获取房户分页列表
  getHouseholdPage(params?: any) {
    return api.get('/api/region/households', { params })
  },

  // 获取房户列表
  getHouseholdList(params?: any) {
    return api.get('/api/region/households', { params })
  },

  // 获取房户详情
  getHouseholdDetail(id: number) {
    return api.get(`/api/region/households/${id}`)
  },

  // 新增房户
  addHousehold(data: any) {
    return api.post('/api/region/households', data)
  },

  // 更新房户
  updateHousehold(id: number, data: any) {
    return api.put(`/api/region/households/${id}`, data)
  },

  // 更新房户（优化版）
  updateHouseholdOptimized(id: number, data: any) {
    return api.put(`/api/region/households/${id}/update`, data)
  },

  // 删除房户
  deleteHousehold(id: number) {
    return api.delete(`/api/region/households/${id}`)
  },

  // 根据单元ID获取房户列表
  getHouseholdsByUnit(unitId: number) {
    return api.get(`/api/region/units/${unitId}/households`)
  },

  // 批量更新房户户型
  batchUpdateHouseType(householdIds: number[], houseTypeId: number) {
    return api.put('/api/region/households/batch/house-type', {
      householdIds,
      houseTypeId
    })
  },

  // ==================== 房户详情Tab页接口 ====================

  // 获取房户业主列表
  getHouseholdOwners(householdId: number, current: number = 1, size: number = 10) {
    return api.get(`/api/region/households/${householdId}/owners`, {
      params: { current, size }
    })
  },

  // 获取房户家庭成员列表
  getHouseholdFamilyMembers(householdId: number, current: number = 1, size: number = 10) {
    return api.get(`/api/region/households/${householdId}/family-members`, {
      params: { current, size }
    })
  },

  // 获取房户租客列表
  getHouseholdTenants(householdId: number, current: number = 1, size: number = 10) {
    return api.get(`/api/region/households/${householdId}/tenants`, {
      params: { current, size }
    })
  }
} 